package com.ruoyi.project.query.paeaDsNewOldAccount.controller;

import java.util.ArrayList;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.query.paeaDsNewOldAccount.domain.PaeaDsNewOldAccount;
import com.ruoyi.project.query.paeaDsNewOldAccount.service.IPaeaDsNewOldAccountService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 新旧账号Controller
 *
 * @author gang.wei
 * @date 2020-04-06
 */
@Controller
@RequestMapping("/query/paeaDsNewOldAccount")
public class PaeaDsNewOldAccountController extends BaseController
{
    private String prefix = "query/paeaDsNewOldAccount";

    @Autowired
    private IPaeaDsNewOldAccountService paeaDsNewOldAccountService;

    @RequiresPermissions("query:paeaDsNewOldAccount:view")
    @GetMapping()
    public String paeaDsNewOldAccount()
    {
        return prefix + "/paeaDsNewOldAccount";
    }

    /**
     * 查询新旧账号列表
     */
    @RequiresPermissions("query:paeaDsNewOldAccount:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PaeaDsNewOldAccount paeaDsNewOldAccount)
    {
        return getDataTable(new ArrayList<PaeaDsNewOldAccount>());
    }
    /**
     * 查询新旧账户列表
     */
    @RequiresPermissions("query:paeaDsNewOldAccount:queryDsNewOldAccount")
    @PostMapping("/queryDsNewOldAccount")
    @ResponseBody
    public TableDataInfo queryPaeaDsNewOldAccount(PaeaDsNewOldAccount paeaDsNewOldAccount)
    {
        QueryWrapper queryWrapper = new QueryWrapper<PaeaDsNewOldAccount>();
        if(StringUtils.isNotEmpty(paeaDsNewOldAccount.getNewAccount())){queryWrapper.like("new_account",paeaDsNewOldAccount.getNewAccount());}
        if(StringUtils.isNotEmpty(paeaDsNewOldAccount.getOldAccount())){queryWrapper.like("old_account",paeaDsNewOldAccount.getOldAccount());}
        startPage();
        List<PaeaDsNewOldAccount> list = paeaDsNewOldAccountService.list(queryWrapper);
        return getDataTable(list);
    }
    /**
     * 导出新旧账号列表
     */
    @RequiresPermissions("query:paeaDsNewOldAccount:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PaeaDsNewOldAccount paeaDsNewOldAccount)
    {
        List<PaeaDsNewOldAccount> list = paeaDsNewOldAccountService.list(new QueryWrapper<>(paeaDsNewOldAccount));
        ExcelUtil<PaeaDsNewOldAccount> util = new ExcelUtil<PaeaDsNewOldAccount>(PaeaDsNewOldAccount.class);
        return util.exportExcel(list, "paeaDsNewOldAccount");
    }

    /**
     * 新增新旧账号
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存新旧账号
     */
    @RequiresPermissions("query:paeaDsNewOldAccount:add")
    @Log(title = "新旧账号", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PaeaDsNewOldAccount paeaDsNewOldAccount)
    {
        return toAjax(paeaDsNewOldAccountService.saveOrUpdate(paeaDsNewOldAccount));
    }
}
